﻿using System;
using System.Collections.Generic;


class MatrixNxN_B
{
    static public void printmatrix(int[,] matr)
    {
        for (int i = 0; i < matr.GetLength(0); i++)
        {
            for (int j = 0; j < matr.GetLength(1); j++)
            {
                Console.Write("{0,4}", matr[i, j]);
            }
            Console.WriteLine();
        }
    }
    static void Main()
    {
        Console.WriteLine("Enter the dimention of the matrix:");
        int dimention = int.Parse(Console.ReadLine());
        int[,] Matrix = new int[dimention, dimention];
        int i = 1;
        for (int col = 0; col < Matrix.GetLength(1); col++)
        {
            if (col % 2 == 0)
            {
                for (int row = 0; row < Matrix.GetLength(0); row++)
                {
                    Matrix[row, col] = i;
                    i++;
                }
            }
            else
            {
                for (int row = Matrix.GetLength(0) - 1; row >= 0; row--)
                {
                    Matrix[row, col] = i;
                    i++;
                }
            }
        }
        Console.WriteLine();
        printmatrix(Matrix);
        Console.WriteLine();
    }

}

